package io.renren.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.dao.ArticalDao;
import io.renren.entity.ArticalEntity;
import io.renren.entity.Result;
import io.renren.service.ArticalService;
import io.renren.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.List;
import java.util.Map;

/**
 * describe:
 * create @ kylin  2019/02/28
 */
@RestController
@RequestMapping(value = "/api/artical")
@Api(tags="文章列表")
public class ApiArticalController {

    @Autowired
    private ArticalService articalService;

    @GetMapping(value = "/index")
    @ApiOperation("首页")
    public Result index(){
        return ResultUtil.success(this.articalService.findAll());
    }

    @GetMapping("/addReadNum/{id}")
    @ApiOperation("阅读量+1")
    public Result addReadNum(@PathVariable("id")Integer id){

        return ResultUtil.success(this.articalService.addReadNum(id));
    }

    @GetMapping("/getartical/{id}")
    @ApiOperation("获取文章信息")
    public Result getartical(@PathVariable("id") Integer id){
        QueryWrapper<ArticalEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ArticalEntity::getId,id);
        return ResultUtil.success(this.articalService.getOne(queryWrapper));
    }

    @ApiOperation(value = "统计数据库中有多少条手记")
    @GetMapping(value = "/count")
    public Result<ArticalEntity> articalCount() throws Exception{
        //一次增加7条数据
        return ResultUtil.success(articalService.articalCount());
    }

    @ApiOperation(value = "页面滑到底部，加载数据")
    @GetMapping(value = "artical/addData/{id}")
    public Result<ArticalEntity> addArticalListNum(@PathVariable("id") Integer id) throws Exception{
        //一次增加7条数据
        return ResultUtil.success(articalService.addArticalListNum(id));
    }
}
